package org.swingDemo;

import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

public class DateFormatDemo {

    public static void displayDate(Locale locale) {
        Date today;
        String dateOut;
        DateFormat dateFormat;

        dateFormat = DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
        today = new Date();
        dateOut = dateFormat.format(today);
        System.out.println(dateOut + "  " + locale);
    }

    public static void showDateStyles(Locale locale) {
        Date today = new Date();
        String result;
        DateFormat dateFormat;

        int[] styles = {
                DateFormat.DEFAULT,
                DateFormat.SHORT,
                DateFormat.MEDIUM,
                DateFormat.LONG,
                DateFormat.FULL
        };

        System.out.println();
        System.out.println("Locale: " + locale);
        System.out.println();

        for (int style : styles) {
            dateFormat = DateFormat.getDateInstance(style, locale);
            result = dateFormat.format(today);
            System.out.println(result);
        }
    }

    public static void showTimeStyles(Locale locale) {
        Date today = new Date();
        String result;
        DateFormat dateFormat;

        int[] styles = {
                DateFormat.DEFAULT,
                DateFormat.SHORT,
                DateFormat.MEDIUM,
                DateFormat.LONG,
                DateFormat.FULL
        };

        System.out.println();
        System.out.println("Locale: " + locale);
        System.out.println();

        for (int style : styles) {
            dateFormat = DateFormat.getTimeInstance(style, locale);
            result = dateFormat.format(today);
            System.out.println(result);
        }
    }

    public static void showBothStyles(Locale locale) {
        Date today = new Date();
        String result;
        DateFormat dateFormat;

        int[] styles = {
                DateFormat.DEFAULT,
                DateFormat.SHORT,
                DateFormat.MEDIUM,
                DateFormat.LONG,
                DateFormat.FULL
        };

        System.out.println();
        System.out.println("Locale: " + locale);
        System.out.println();

        for (int style : styles) {
            dateFormat = DateFormat.getDateTimeInstance(style, style, locale);
            result = dateFormat.format(today);
            System.out.println(result);
        }
    }

    public static void main(String[] args) {
        Locale[] locales = {
                new Locale("zh", "CN"),
                new Locale("fr", "FR"),
                new Locale("de", "DE"),
                new Locale("en", "US")
        };

        for (Locale locale : locales) {
            displayDate(locale);
        }

        for (Locale locale : locales) {
            showDateStyles(locale);
        }

        for (Locale locale : locales) {
            showTimeStyles(locale);
        }

        for (Locale locale : locales) {
            showBothStyles(locale);
        }
    }
}
